﻿using System.Collections.Generic;
using System.IO;
using System.Xml.Serialization;

namespace Helper
{
   public class XMLWriter
   {
      private readonly XmlSerializer serializer;
      private FileStream filestream;

      public XMLWriter()
      {
         serializer = new XmlSerializer(typeof(List<KukaCoordData>));
      }

      public string writeData(string filepath, List<KukaCoordData> coords)
      {
         string returns = "";

         filestream = new FileStream(@filepath, FileMode.Create);

         try
         {
            serializer.Serialize(filestream, coords);
            returns = "Coordinates saved in XML-file.";
         }
         catch (IOException exception)
         {
            returns = "- Error - " +exception.Message;
         }

         filestream.Close();

         return returns;
      }
   }
}
